﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace EditColumn.ConnectColumnBream
{
	internal class SwitchView
	{
		public SwitchView(ExternalCommandData commandData)
		{
			this.m_commandData = commandData;
			this.m_uiDoc = commandData.Application.ActiveUIDocument;
			this.m_doc = this.m_uiDoc.Document;
			this.m_uiApp = commandData.Application;
		}

		public bool IsOpenViewPlan()
		{
			ViewPlan viewPlan = this.m_doc.ActiveView as ViewPlan;
			if (viewPlan != null)
			{
				return true;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_doc);
			filteredElementCollector.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Views)).WhereElementIsNotElementType();
			foreach (Element element in filteredElementCollector)
			{
				View view = (View)element;
				ViewPlan viewPlan2 = view as ViewPlan;
				if (viewPlan2 != null && viewPlan2.GenLevel != null)
				{
					string title = viewPlan2.Title;
					this.m_dicDocViewPlan.Add(title, viewPlan2);
				}
			}
			return false;
		}

		public void OpenViewPlan(string ViewPlanName)
		{
			this.m_uiApp.ActiveUIDocument.ActiveView = this.m_dicDocViewPlan[ViewPlanName];
		}

		private ExternalCommandData m_commandData;

		private UIDocument m_uiDoc;

		private Document m_doc;

		private UIApplication m_uiApp;

		public Dictionary<string, ViewPlan> m_dicDocViewPlan = new Dictionary<string, ViewPlan>();
	}
}
